home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / python-support / gnome-orca / orca / phonnames.py < prev    next >
Encoding:
Python Source  |  2009-04-13  |  3.0 KB  |  86 lines

  1. # Orca
  2. #
  3. # Copyright 2006-2008 Sun Microsystems Inc.
  4. #
  5. # This library is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU Library General Public
  7. # License as published by the Free Software Foundation; either
  8. # version 2 of the License, or (at your option) any later version.
  9. #
  10. # This library is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. # Library General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Library General Public
  16. # License along with this library; if not, write to the
  17. # Free Software Foundation, Inc., Franklin Street, Fifth Floor,
  18. # Boston MA  02110-1301 USA.
  19.  
  20. """Provides getPhoneticName method that maps each letter of the
  21. alphabet into its localized phonetic equivalent."""
  22.  
  23. __id__        = "$Id: phonnames.py 3882 2008-05-07 18:22:10Z richb $"
  24. __version__   = "$Revision: 3882 $"
  25. __date__      = "$Date: 2008-05-07 14:22:10 -0400 (Wed, 07 May 2008) $"
  26. __copyright__ = "Copyright (c) 2006-2008 Sun Microsystems Inc."
  27. __license__   = "LGPL"
  28.  
  29. from orca_i18n import _ # for gettext support
  30.  
  31. # Translators: this is a structure to assist in the generation of
  32. # spoken military-style spelling.  For example, 'abc' becomes 'alpha
  33. # bravo charlie'.
  34. #
  35. # It is a simple structure that consists of pairs of
  36. #
  37. # letter : word(s)
  38. #
  39. # where the letter and word(s) are separate by colons and each
  40. # pair is separated by commas.  For example, we see:
  41. #
  42. # a : alpha, b : bravo, c : charlie,
  43. #
  44. # And so on.  The complete set should consist of all the letters from
  45. # the alphabet for your language paired with the common
  46. # military/phonetic word(s) used to describe that letter.
  47. #
  48. # The Wikipedia entry
  49. # http://en.wikipedia.org/wiki/NATO_phonetic_alphabet has a few
  50. # interesting tidbits about local conventions in the sections
  51. # "Additions in German, Danish and Norwegian" and "Variants".
  52. #
  53. __phonlist = _("a : alpha, b : bravo, c : charlie, "
  54.                "d : delta, e : echo, f : foxtrot, "
  55.                "g : golf, h : hotel, i : india, "
  56.                "j : juliet, k : kilo, l : lima, "
  57.                "m : mike, n : november, o : oscar, "
  58.                "p : papa, q : quebec, r : romeo, "
  59.                "s : sierra, t : tango, u : uniform, "
  60.                "v : victor, w : whiskey, x : xray, "
  61.                "y : yankee, z : zulu")
  62.  
  63. __phonnames = {}
  64.  
  65. for __pair in __phonlist.split(','):
  66.     __w = __pair.split(':')
  67.     __phonnames [__w[0].strip()] = __w[1].strip()
  68.  
  69. def getPhoneticName(character):
  70.     """Given a character, return its phonetic name, which is typically
  71.     the 'military' term used for the character.
  72.  
  73.     Arguments:
  74.     - character: the character to get the military name for
  75.  
  76.     Returns a string representing the military name for the character
  77.     """
  78.  
  79.     if isinstance(character, unicode):
  80.         character = character.encode("UTF-8")
  81.  
  82.     try:
  83.         return __phonnames[character]
  84.     except:
  85.         return character
  86.